<template>
  <a-card :bordered='false'>
    <search :config='searchConfig' @search='search' @getHeight='getHeight' />
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config='tableToolbar'
        :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button v-has="'proStock:add'" @click='handleAdd'>新增</a-button>
            <a-button v-has="'proStock:delete'" @click='batchDel'>删除</a-button>
            <a-button type="primary" @click="handleExportXls('商品库存')">模板下载</a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"
                      :action="url.importExcelUrl" @change="handleImportExcel">
              <a-button type="primary">导入</a-button>
            </a-upload>

            <!--            <a-button type='primary' @click=''>同步</a-button>-->
            <a-button type="primary" @click="downExportXls('sfaCommodity_service')">导出</a-button>
          </div>
        </template>
        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.goodsCode }}</a>
        </template>
        <template #date='{ row,rowIndex }'>
          {{ row.startDate }} ~ {{ row.endDate }}
        </template>
        <template #action='{ row ,rowIndex}'>
          <a v-has="'business:log'" @click='handleEdit(row)'>调整</a>
          <a-divider type='vertical' />
          <a v-has="'business:log'" href='javascript:' @click='expenseDetails(row)'>明细</a>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <business-log ref='businessLog'></business-log>
    <policys ref="policysModal" v-bind="policysData"></policys>
    <product-stock-modal ref="modalForm" @ok="modalFormOk"></product-stock-modal>
  </a-card>
</template>

<script>
import policys from '@comp/cn-components/Policys'
import ProductStockModal from './modules/ProductStockModal'
import { PageListMixin } from '@/mixins/PageListMixin'

export default {
  name: 'proMinPrice',
  mixins: [PageListMixin],
  components: {
    ProductStockModal,policys
  },
  data() {
    return {
      description: '库存管理',
      searchConfig: [
        {
          type: 'input',
          name: 'goodsCode',
          placeholder: '商品编码'
        },
        {
          type: 'input',
          name: 'goodsName',
          placeholder: '商品名称'
        },

        {
          type: 'date-range', //范围选择
          range: ['startDate', 'endDate'],
          name: 'range',
          format: 'YYYY-MM-DD',
          placeholder: ['更新开始时间', '更新结束时间']
        }
      ],
      columns: [
        { type: 'checkbox', width: 60, fixed: 'left' },
        {
          title: '商品编码',
          field: 'goodsCode',
          minWidth: 100,
          fixed: 'left',
          slots: { default: 'detail' }
        },
        {
          title: '商品名称',
          minWidth: 100,
          field: 'goodsName'
        },
        {
          title: '库存数量',
          minWidth: 100,
          field: 'inventoryBalance'
        },
        {
          title: '库存单位',
          minWidth: 100,
          field: 'basicUnitStr'
        },
        {
          title: '创建人',
          minWidth: 100,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth: 100,
          field: 'createTime'
        },
        {
          title: '更新人',
          minWidth: 100,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth: 100,
          field: 'updateTime'
        },
        {
          title: '操作',
          align: 'center',
          minWidth: 120,
          fixed: 'right',
          slots: { default: 'action' }
        }
      ],
      url: {
        list: window._CONFIG['domianSfaURL'] + '/sfaCommodityController/findPageList',
        detail: window._CONFIG['domianSfaURL'] + '/sfaCommodityController/getInfo',
        delete: window._CONFIG['domianSfaURL'] + '/sfaCommodityController/delete',
        deleteBatch: window._CONFIG['domianSfaURL'] + '/sfaCommodityController/deleteBatch',
        exportXlsUrl: window._CONFIG['domianSfaURL'] + '/sfaCommodityController/exportXls',
        importExcelUrl: window._CONFIG['domianSfaURL'] + '/sfaCommodityController/importExcel',
      }
    }
  },
  created() {

  },
  computed: {
    policysData() {
      return {
        title: '库存明细',
        width: `${50}%`,
        rowKey: 'id',
        tableShowSelect:false,
        way: 'post',
        tableUrl: window._CONFIG['domianSfaURL'] + '/sfaCommodityController/findPageFlowingList',
        tableColums: [
          {
            title: '类型',
            align: 'center',
            dataIndex: 'dataTypeStr'
          },
          {
            title: '更新人',
            align: 'center',
            dataIndex: 'createName'
          },
          {
            title: '更新时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'sfaOrderCode',
          },
          {
            title: '库存明细',
            align: 'center',
            dataIndex: 'changeQuantity'
          },
          {
            title: '库存数量',
            align: 'center',
            dataIndex: 'afterQuantity'
          },
        ],
        haveSelect:{},
        multiple: false

      }
    }
  },
  methods:{
    expenseDetails(cord){
      let params = {
        goodsCode:cord.goodsCode
      }
      this.$refs.policysModal.edit(params)

    },
    handleEdit:async function(row) {
      this.$refs.modalForm.title='调整'
      this.$refs.modalForm.edit(row)
      this.$refs.modalForm.disableSubmit = true
    },

  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>